/**
 * Created by hps on 17-4-27.
 */
public class BracketChecker {
    private String input;

    public BracketChecker(String input) {
        this.input = input;
    }

    public void check() {
        int stackSize = input.length();
        StackX1 stackX1 = new StackX1(stackSize);

        for (int i = 0; i < stackSize; i++) {
            char ch = input.charAt(i);
            switch (ch) {
                case '{':
                case  '(':
                case '[':
                    stackX1.push(ch);
                    break;
                case '}':
                case ')':
                case ']':
                    if(!stackX1.isEmpty()) {
                        char c = stackX1.pop();
                        if((ch == '}' && c != '{') ||
                                (ch == ')' && c != '(') ||
                                (ch == ']' && c !='[')) {
                            System.out.println("Error: " + ch + " at " + i);
                            return;
                        }
                    } else {
                        System.out.println("Error: " + ch + " at " + i);
                        return;
                    }
                    break;
                default:
                    break;
            }
        }

        if(!stackX1.isEmpty()) {
            System.out.println("Error: missing right delimiter");
        }
    }
}
